<?php
namespace app\api\controller\v1\admin\auth;
use app\api\controller\v1\Init;
use fast\Random;


class Rule extends Init
{

	public function _initialize() {
		parent::_initialize();
		$this->model = model('admin/auth_rule', 'service');
	}

	/* 成员列表 */
	public function lists() {
		$maps = [];
		if($this->params['keyword']) {
			$maps['name|title|remark'] = ['like', '%'.$this->params['keyword'].'%'];
		}
		$result = $this->model->lists($maps, $this->params['limit'], $this->params['page']);
		return $this->response(lang('Operation completed'), $result);
	}

	/* 成员详情 */
	public function info($id = 0) {
		$info = $this->model->get(['id' => $id]);
		return $this->response(lang('Operation completed'), $info);
	}

	/* 成员添加 */
	public function add() {
		$post = $this->request->post();
		$result = $this->model->add($post, [], 'add');
		if($result === false) {
			return $this->response($this->model->getError());
		}
		return $this->response(lang('Operation completed'), $result);
	}

	/* 成员编辑 */
	public function edit() {
		$post = $this->request->post();
		$result = $this->model->edit($post, ['id' => $post['id']], 'edit');
		if($result === false) {
			return $this->response($this->model->getError());
		}
		return $this->response(lang('Operation completed'), $result);
	}

	/* 成员删除 */
	public function delete() {
		$id = $this->request->post('id/s');
		$ids = explode(",", $id);
		$maps = ['id' => ['in', $ids]];
		$result = $this->model->where($maps)->delete();
		if($result === false) {
			return $this->response($this->model->getError());
		}
		return $this->response(lang('Operation completed'), $result);
	}
}